home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / graftxt.com / GRAFTEX2.ASM < prev    next >
Encoding:
Assembly Source File  |  1989-07-06  |  6.4 KB  |  204 lines

  1. data   segment word public
  2.        extrn   pitch:WORD     ; number of bytes per scan line
  3. data   ends
  4.  
  5.  
  6.  
  7. code      segment   byte public
  8. assume    cs:code,ds:data
  9. public    gsol
  10. page 60,132
  11. ;                   val val val     val      VAR    VAR
  12. ; procedure gsol(gdx,gdy,color,fontlines,fontbase,instring);
  13.  
  14. gdx       equ  [BP+20]
  15. gdy       equ  [BP+18]
  16. backgnd   equ  [BP+16]
  17. color     equ  [BP+14]
  18. fontlines equ  [BP+12]
  19. fontbase  equ  [BP+8]
  20. instring  equ  [BP+4]
  21.  
  22. gsol proc    NEAR
  23.  
  24.      push      bp
  25.      mov       bp,sp
  26.      push      ds
  27. ;
  28.      mov     ax,pitch
  29.      mov     CS:[lpitch],ax    ; save pitch in CS: since DS is going to change
  30.  
  31.  
  32. ; Calculate byte address (segment & offset) and bit mask
  33.  
  34. ;
  35.      mov     dx,040h         ; bios data segment
  36.      mov     ds,dx
  37.      mov     si,062h
  38.      mov     al,[si]       ; get active display page
  39.  
  40.      mov     dx,0A000h       ; base page of EGA/VGA memory
  41. ;
  42.      or      al,al           ; set flags
  43.      jz      page0           ; if zero, skip ofset add
  44.      add     dh,8            ; ofset to second page base of A800h
  45.  
  46. page0:
  47.      mov     ds,dx           ; DS := EGA/VGA buffer segment address
  48.  
  49.      mov     dx,3CEh         ; Graphics Controller port address
  50.      mov     ax,5
  51.      out     dx,al           ; select register 5 (mode)
  52.  
  53.      inc     dx              ; dx = 3CFh
  54.      in      al,dx           ; read current mode
  55.      and     al,0FCh
  56.      or      al,02h          ; set to mode 2
  57.      out     dx,al
  58.  
  59.      dec     dx              ; dx = 3CEh
  60.      mov     al,8
  61.      out     dx,al           ; leave pointing to bit mask register
  62.  
  63.      mov     dx,3C4h         ; Sequencer/Map Mode port address
  64.      mov     ax,0F02h
  65.      out     dx,ax           ; Select "Map Mask" register 2, enable all planes
  66.  
  67.  
  68. ;
  69.      mov     ax,gdx          ; get X address from stack frame
  70.      shr     ax,1
  71.      shr     ax,1
  72.      shr     ax,1            ; compute memory address ofset  AX := x/8
  73.      mov     bx,ax           ; save back on stack
  74. ;
  75.      les     SI,instring     ; get doulbleword base address of string
  76.      xor     ch,ch           ; clear ch
  77.      mov     cl,byte ptr ES:[si]  ; points to length of string
  78.      or      cl,cl        ; set flags
  79.      jz         nullstring      ; if length is zero, skip everything
  80.  
  81.      mov     ax,gdy          ; get Y address (a pixel row)
  82.      add     ax,fontlines           ; add in lines in font as ofset to Y value
  83.      dec     ax              ; subtract 1 because cx is 1 based inst. of 0
  84.      mov     dx,CS:[lpitch]
  85.      mul     dx              ; AX := (y * 80)  ([pitch] bytes per row)
  86.  
  87.      add     ax,bx           ; AX := (y * 80) + x/8          (offset)
  88.  
  89.      mov     di,ax           ; save EGA/VGA memory ofset in DI
  90.  
  91. ; Get the "Bit Mask" register address
  92.      mov     dx,3CFh         ; bit mask register
  93.  
  94.  
  95.  
  96. strloop:                     ; loop for number of characters in string
  97.      push    CX              ; save string count for outer loop
  98.      inc     SI              ; make si point to nextchar
  99.      mov     bl,byte ptr ES:[SI]      ; SI points to next char - read into bx
  100.      inc     bl              ; increment char code : draw char from bot to top
  101.      mov     ax,fontlines    ; get number of lines/char in font
  102.      mov     cx,ax           ; keep for use as char-loop counter
  103.      mul     bl              ; ax := bl (character) * al (bytes/char)
  104.      mov     bx,ax           ; leave font character ofset in BX
  105.      push    ES              ; save char string seg.
  106.      push    SI              ; save char string pointer
  107.      push    DI              ; save EGA/VGA destination
  108. ;
  109. ; loop for the number of lines
  110. ;
  111.  
  112.      les     SI,fontbase     ; get dblword base address of font
  113. ;
  114. ;
  115.  
  116.      mov     ah,0ffh         ; bit mask constant
  117.      dec     cx              ; one less pass thru loop, due to early latch read
  118.  
  119.      dec     bx              ; move UP to next scanline in font
  120.  
  121.      mov     al,ah
  122.      out     dx,al           ; enable all bits in bit mask into reg 8
  123. ;
  124.      mov     al,backgnd
  125.      mov     [di],al         ; Set all bits to "backgnd color".
  126.  
  127.      mov     al,[di]         ; Latch the bit plane data with dummy read
  128.                              ; latch only once for all writes this character
  129.  
  130. charloop:                    ; loop through the font's scanlines bottom to top
  131.  
  132.  
  133. ; Set bits in the appropriate bit planes by writing color value to EGA/VGA memory
  134.  
  135.      mov     al,ES:[BX][SI]  ; get bit mask byte from font: bx=font char ofs
  136.      out     dx,al           ; load bit mask into reg 8
  137.  
  138.      mov     al,color
  139.      mov     [di],al         ; write foreground color with bit mask.
  140.  
  141. ;                                                           8
  142.      sub     di,CS:[lpitch]         ; move up one line in EGA/VGA memory
  143.  
  144.      dec     bx              ; move UP to next scanline in font
  145.  
  146.      mov     al,ah
  147.      out     dx,al           ; enable all bits in bit mask, reg 8
  148. ;
  149.      mov     al,backgnd
  150.      mov     [di],al         ; Set all bits to "backgnd color".
  151.  
  152.  
  153.      loop    charloop        ; decrement cx and do next scanline
  154.  
  155.                              ; perform final foreground write
  156.  
  157.      mov     al,ES:[BX][SI]  ; get bit mask byte from font: bx=font char ofs
  158.      out     dx,al           ; load bit mask into reg 8
  159.  
  160.      mov     al,color
  161.      mov     [di],al         ; write foreground color with bit mask.
  162.  
  163.  
  164.      pop     DI              ; get back EGA/VGA destination
  165.      inc     DI              ; move screen position to next char over
  166.  
  167.      pop     SI              ; pop character pointer
  168.      pop     ES              ;  "     "      segement
  169.  
  170.      pop     CX              ; get outer loop - counting chars in string
  171.      loop    strloop
  172.  
  173. nullstring:
  174. ; Restore default EGA/VGA graphics status
  175.  
  176.  
  177.  
  178.  
  179.      mov     dx,3CEh         ; Graphics Controller port address
  180.      mov     ax,5
  181.      out     dx,al           ; select register 5 (mode)
  182.  
  183.      inc     dx              ; dx = 3CFh
  184.      in      al,dx           ; read current mode
  185.      and     al,0FCh         ; set to write mode 0
  186.      out     dx,al
  187.  
  188.      dec     dx              ; dx = 3CEh
  189.      mov     ax,0FF08h        ; reset bitmask register to all on
  190.      out     dx,ax           ; ... Graphics Controller register 8
  191.  
  192.      pop       ds
  193.      pop       bp
  194.      ret       16d
  195. gsol endp
  196.  
  197. lpitch  dw      0               ; local CS storage for pitch
  198.  
  199.  
  200. code ends
  201.  
  202.      end
  203.  
  204.